//
//  BaseUINavigationController.m
//  CWCalendar
//
//  Created by Calvin on 9/28/15.
//  Copyright (c) 2015 Calvin. All rights reserved.
//

#import "BaseUINavigationController.h"

@interface BaseUINavigationController ()

@end

@implementation BaseUINavigationController
/**
 *  @author Calvin, 15-09-28 16:09:48
 *
 *  <#Description#>
 *
 *  @param rootViewController <#rootViewController description#>
 *
 *  @return <#return value description#>
 */
-(instancetype)initWithRootViewController:(UIViewController *)rootViewController
{
    UINavigationController *nav = [super initWithRootViewController:rootViewController];
    nav.interactivePopGestureRecognizer.delegate = self;
    nav.delegate = self;
    return self;
}

/**
 *  @author Calvin, 15-09-28 16:09:52
 *
 *  <#Description#>
 *
 *  @param navigationController <#navigationController description#>
 *  @param viewController       <#viewController description#>
 *  @param animated             <#animated description#>
 */
-(void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if ( 1== navigationController.viewControllers.count) {
        self.currentShowVC = nil;
    }
    else
    {
        self.currentShowVC = viewController;
    }
}

/**
 *  @author Calvin, 15-09-28 16:09:56
 *
 *  <#Description#>
 *
 *  @param gestureRecognizer <#gestureRecognizer description#>
 *
 *  @return <#return value description#>
 */
-(BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
    if (gestureRecognizer == self.interactivePopGestureRecognizer) {
        return (self.currentShowVC == self.topViewController);
    }
    return YES;
}

/**
 *  @author Calvin, 15-09-28 16:09:59
 *
 *  <#Description#>
 *
 *  @param gestureRecognizer      <#gestureRecognizer description#>
 *  @param otherGestureRecognizer <#otherGestureRecognizer description#>
 *
 *  @return <#return value description#>
 */
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    if ([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]&&[otherGestureRecognizer isKindOfClass:[UIScreenEdgePanGestureRecognizer class]] ) {
        return YES;
    }
    else
    {
        return NO;
    }
}
@end
